/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mundialfp.view.pais;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import mundialfp.view.tables.paisABM.PaisTableSorter;
import mundialfp.view.tables.TableCustom3;
import mundialfp.view.tables.ranking.TableRankingManager;

/**
 *
 * @author pferraz
 */
public class RankingView extends javax.swing.JFrame {

    private final TableCustom3 tblListaPais;
    private final PaisTableSorter paisTableSorter;
    private final TableRankingManager tGenerator;
    private final RankingManager manager;

    int BANDERA_HEIGHT = 30;
    int BANDERA_WIDTH = 50;

    /**
     * Creates new form RankingView
     */
    public RankingView() {
        tGenerator = new TableRankingManager();
        paisTableSorter = new PaisTableSorter();
        this.tblListaPais = new TableCustom3(4);
        manager = new RankingManager(this);
        initComponents();
        formLoad();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlRankingFIFA = new javax.swing.JPanel();
        txtPaisQuickSearch = new javax.swing.JTextField();
        lblBallLoad = new javax.swing.JLabel();
        lblLoad = new javax.swing.JLabel();
        pnlTable = new javax.swing.JPanel();

        setTitle("Ranking FIFA");
        setResizable(false);

        pnlRankingFIFA.setBackground(java.awt.Color.white);

        txtPaisQuickSearch.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
        txtPaisQuickSearch.setForeground(java.awt.Color.gray);
        txtPaisQuickSearch.setText("Búsqueda rápida ...");
        txtPaisQuickSearch.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtPaisQuickSearchFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtPaisQuickSearchFocusLost(evt);
            }
        });

        lblBallLoad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/211.GIF"))); // NOI18N

        lblLoad.setFont(new java.awt.Font("Trebuchet MS", 1, 10)); // NOI18N
        lblLoad.setText("CARGANDO");

        pnlTable.setBackground(java.awt.Color.white);

        javax.swing.GroupLayout pnlTableLayout = new javax.swing.GroupLayout(pnlTable);
        pnlTable.setLayout(pnlTableLayout);
        pnlTableLayout.setHorizontalGroup(
            pnlTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 603, Short.MAX_VALUE)
        );
        pnlTableLayout.setVerticalGroup(
            pnlTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 512, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout pnlRankingFIFALayout = new javax.swing.GroupLayout(pnlRankingFIFA);
        pnlRankingFIFA.setLayout(pnlRankingFIFALayout);
        pnlRankingFIFALayout.setHorizontalGroup(
            pnlRankingFIFALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlRankingFIFALayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtPaisQuickSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlRankingFIFALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblLoad)
                    .addComponent(lblBallLoad))
                .addGap(65, 65, 65))
            .addComponent(pnlTable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnlRankingFIFALayout.setVerticalGroup(
            pnlRankingFIFALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlRankingFIFALayout.createSequentialGroup()
                .addGroup(pnlRankingFIFALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlRankingFIFALayout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(txtPaisQuickSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlRankingFIFALayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lblBallLoad)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlTable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlRankingFIFA, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlRankingFIFA, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void txtPaisQuickSearchFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPaisQuickSearchFocusLost
        // TODO add your handling code here:
        if (txtPaisQuickSearch.getText().length() == 0) {
            txtPaisQuickSearch.setText("Búsqueda rápida ...");
            txtPaisQuickSearch.setForeground(Color.GRAY);
        }
    }//GEN-LAST:event_txtPaisQuickSearchFocusLost

    private void txtPaisQuickSearchFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPaisQuickSearchFocusGained
        txtPaisQuickSearch.setText("");
        txtPaisQuickSearch.setForeground(Color.BLACK);
    }//GEN-LAST:event_txtPaisQuickSearchFocusGained

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RankingView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RankingView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RankingView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RankingView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new RankingView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblBallLoad;
    private javax.swing.JLabel lblLoad;
    private javax.swing.JPanel pnlRankingFIFA;
    private javax.swing.JPanel pnlTable;
    private javax.swing.JTextField txtPaisQuickSearch;
    // End of variables declaration//GEN-END:variables

    private void formLoad() {
        this.pnlTable.setVisible(false);
        manager.getRankingFIFA();
        enableComponents(getPnlRankingFIFA(), true);
        tblListaPais.requestFocus();
    }

    public TableCustom3 getTblListaPais() {
        return tblListaPais;
    }

    public PaisTableSorter getPaisTableSorter() {
        return paisTableSorter;
    }

    public TableRankingManager gettGenerator() {
        return tGenerator;
    }

    public int getBANDERA_HEIGHT() {
        return BANDERA_HEIGHT;
    }

    public int getBANDERA_WIDTH() {
        return BANDERA_WIDTH;
    }

    public JLabel getLblBallLoad() {
        return lblBallLoad;
    }

    public JLabel getLblLoad() {
        return lblLoad;
    }

    public JPanel getPnlRankingFIFA() {
        return pnlRankingFIFA;
    }

    public void enableComponents(Container container, boolean enable) {
        Component[] components = container.getComponents();
        for (Component component : components) {
            if (!enable) {
                if (component != lblBallLoad && component != lblLoad) {
                    component.setEnabled(enable);
                }
            } else {
                component.setEnabled(enable);
            }

            if (component instanceof Container) {
                enableComponents((Container) component, enable);
            }
        }
    }

    public JTextField getTxtPaisQuickSearch() {
        return txtPaisQuickSearch;
    }

    public JPanel getPnlTable() {
        return pnlTable;
    }

    
}
